package com.matrix.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class Client {
    private static String str = "请求连接...";
    private static String reply;

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket(InetAddress.getLocalHost(), 9099);
        PrintWriter pw = new PrintWriter(socket.getOutputStream());
        pw.write(socket.getInetAddress().getHostName() + str);
        pw.flush();
        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        while ((reply = br.readLine()) != null) {
            System.out.println("服务器响应：" + reply);
        }
        socket.shutdownInput();

        br.close();
        pw.close();
        socket.close();
    }
}
